﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.actions {
    import Engine.Helpers.*;
    import Classes.*;
    import Engine.*;

    public class ActionBusinessPacing extends NPCAction {

        public static var AVG_IDLE_DELAY_SECONDS:Number = 3;

        protected var m_business:MapResource;
        protected var m_timeStarted:Number;
        protected var m_pacingTimeMs:Number;
        protected var m_waving:Boolean;
        protected var m_checkBusiness:Boolean = false;

        public function ActionBusinessPacing(_arg1:NPC, _arg2:MapResource, _arg3:Boolean=true, _arg4:Number=2147483647, _arg5:Number=0){
            super(_arg1);
            this.m_business = _arg2;
            this.m_waving = _arg3;
            this.m_pacingTimeMs = ((_arg4)!=int.MAX_VALUE) ? (_arg4 * 1000) : int.MAX_VALUE;
            this.m_timeStarted = _arg5;
        }
        public function setCheckBusiness(_arg1:Boolean):ActionBusinessPacing{
            this.m_checkBusiness = _arg1;
            return (this);
        }
        override public function update(_arg1:Number):void{
            if (this.m_timeStarted == 0){
                this.m_timeStarted = GlobalEngine.getTimer();
            };
            var _local2:Vector3 = this.m_business.findValidCrowdPosition();
            var _local3:Number = MathUtil.randomWobble(AVG_IDLE_DELAY_SECONDS, 0.5);
            var _local4:Number = (GlobalEngine.getTimer() - this.m_timeStarted);
            if (_local4 < this.m_pacingTimeMs){
                if (((!(this.m_checkBusiness)) || (((this.m_checkBusiness) && (Global.world.getObjectById(this.m_business.getId())))))){
                    m_npc.getStateMachine().addActions(new ActionNavigateBeeline(m_npc, _local2), new ActionPlayAnimation(m_npc, (this.m_waving) ? "wave" : "idle", _local3), new ActionBusinessPacing(m_npc, this.m_business, this.m_waving, (this.m_pacingTimeMs / 1000), this.m_timeStarted).setCheckBusiness(this.m_checkBusiness));
                };
            };
            m_npc.getStateMachine().popState();
        }

    }
}//package Classes.actions 
